extends Sprite2D

var speed = 400
var angular_speed = PI
var screen_size # Size of the game window.
var notify_fn :Callable

func _init():
	pass

# Called when the node enters the scene tree for the first time.
func _ready():
	screen_size = get_viewport_rect().size
	print(screen_size)
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): 
	var direction = 0
	if Input.is_action_pressed("ui_left"):
		direction = -1
	if Input.is_action_pressed("ui_right"):
		direction = 1

	rotation += angular_speed * direction * delta

	var velocity = Vector2.ZERO
	if Input.is_action_pressed("ui_up"):
		velocity = Vector2.UP.rotated(rotation) * speed

	position += velocity * delta
	position = position.clamp(Vector2.ZERO, screen_size)
	
	if notify_fn.is_valid():
		notify_fn.call(position)
